import request, { type ListQuery, type ListResponse } from "@/utils/request";
import { type AgentItemType } from "./agent";
import { type MerchantType } from "../merchant/merchant";

const EXAMINE_BASE_URL = "/api";

export const ExamineApi = {
  getExamineList: (params: ListQuery) => {
    return request.get<any, ListResponse<ExamineItemType>>(
      `${EXAMINE_BASE_URL}/agent/switch/pending/`,
      {
        params,
      }
    );
  },
  examineApply: (data: ExamineForm) => {
    return request.post<any, ListResponse<ExamineItemType>>(
      `${EXAMINE_BASE_URL}/agent/switch/${data.id}/approve/`,
      data
    );
  },
};

export type ExamineListQuery = {} & ListQuery;

export type ExamineItemType = {
  agent: AgentItemType;
  approve_reason?: string;
  client_type: "supplier" | "merchant";
  created_at: string;
  id: number;
  is_active: boolean;
  merchant?: MerchantType;
  remark: string;
  status: "pending" | "approved" | "rejected";
  supplier: number;
  updated_at: string;
  user: number;
};

export type ExamineForm = {
  id: number | string;
  status: "pass" | "reject";
  approve_reason: string;
};

export default ExamineApi;
